package com.lepu.app.fun.my.adapter;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.core.lib.utils.main.DateUtilBase;
import com.eyzhs.app.R;
import com.lepu.app.fun.my.bean.BeanScoreInfo;

public class AdapterScoreInfo extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	@SuppressWarnings("unused")
	private Context mContext = null;
	private ArrayList<BeanScoreInfo> mArrayList = null;

	public AdapterScoreInfo(Context context, ArrayList<BeanScoreInfo> arrayList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(
					R.layout.my_score_info_activity_listitem, null);

			holder = new ViewHolder();

			TextView nameTextView = (TextView) convertView
					.findViewById(R.id.nameTextView);
			TextView timeTextView = (TextView) convertView
					.findViewById(R.id.timeTextView);
			TextView numberTextView = (TextView) convertView
					.findViewById(R.id.numberTextView);

			holder.nameTextView = nameTextView;
			holder.timeTextView = timeTextView;
			holder.numberTextView = numberTextView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final BeanScoreInfo item = mArrayList.get(position);

		holder.nameTextView.setText(item.CreditsChangeContent);
		holder.timeTextView.setText(DateUtilBase.stringFromDate(DateUtilBase
				.dateFromString(item.CreditsChangeTime,
						DateUtilBase.YEAR_MONTH_DAY),
				DateUtilBase.YEAR_MONTH_DAY));

		if (item.CreditsChange > 0) {
			holder.numberTextView.setText(String.format("+%d",
					item.CreditsChange));
		} else {
			holder.numberTextView.setText(String.valueOf(item.CreditsChange));
		}

		return convertView;
	}

	private static class ViewHolder {
		TextView nameTextView;
		TextView timeTextView;
		TextView numberTextView;
	}
}
